package cn.walls1717.ggkt.vod.controller;

import cn.walls1717.ggkt.model.vod.Chapter;
import cn.walls1717.ggkt.result.Result;
import cn.walls1717.ggkt.vo.vod.ChapterVo;
import cn.walls1717.ggkt.vod.service.ChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程相关接口
 *
 * @author walls1717
 * @since 2022/07/14
 */
@Api(tags = "课程相关接口")
@RestController
@RequestMapping("/admin/vod/chapter")
public class ChapterController {
    @Autowired
    private ChapterService chapterService;

    @ApiOperation("大纲列表")
    @GetMapping("getNestedTreeList/{courseId}")
    public Result<List<ChapterVo>> listTree(@PathVariable Long courseId) {
        List<ChapterVo> chapterVoList = chapterService.listTree(courseId);
        return Result.success(chapterVoList);
    }

    @ApiOperation("添加章节")
    @PostMapping("save")
    public Result<?> saveChapter(@RequestBody Chapter chapter) {
        chapterService.save(chapter);
        return Result.success();
    }

    @ApiOperation("根据id查询章节")
    @GetMapping("get/{id}")
    public Result<Chapter> getChapterById(@PathVariable Long id) {
        Chapter chapter = chapterService.getById(id);
        return Result.success(chapter);
    }

    @ApiOperation("修改章节")
    @PutMapping("update")
    public Result<?> updateChapter(@RequestBody Chapter chapter) {
        chapterService.updateById(chapter);
        return Result.success();
    }

    @ApiOperation("删除章节")
    @DeleteMapping("remove/{id}")
    public Result<?> deleteChapter(@PathVariable Long id) {
        chapterService.removeById(id);
        return Result.success();
    }
}
